package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.dto.PageDto;
import com.qf.mapper.DtsArticleMapper;
import com.qf.pojo.DtsArticle;
import com.qf.service.DtsArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/25 10:27
 */
@Service
public class DtsArticleServiceImpl  implements DtsArticleService {
    @Autowired
    private DtsArticleMapper dtsArticleMapper;
    @Override
    public Page<DtsArticle> selectPage(PageDto pageDto) {
        Page<DtsArticle> dtsArticlePage = new Page<>(pageDto.getPage(), pageDto.getLimit());
        QueryWrapper<DtsArticle> dtsArticleQueryWrapper = new QueryWrapper<>();
        dtsArticleQueryWrapper
                .orderBy(!StringUtils.isEmpty(pageDto.getSort()),"asc".equalsIgnoreCase(pageDto.getOrder()), pageDto.getSort()).like(!StringUtils.isEmpty(pageDto.getName()),"title",pageDto.getName()).eq("deleted",false);
        return dtsArticleMapper.selectPage(dtsArticlePage,dtsArticleQueryWrapper);
    }

    @Override
    public DtsArticle selectDetail(Integer id) {
        return dtsArticleMapper.selectById(id);
    }

    @Override
    public void update(DtsArticle dtsArticle) {
           dtsArticleMapper.updateById(dtsArticle);
    }

    @Override
    public void insert(DtsArticle dtsArticle) {
     dtsArticleMapper.insert(dtsArticle);
    }

    @Override
    public void delete(DtsArticle dtsArticle) {
        dtsArticleMapper.updateById(dtsArticle);
    }
}
